
$(document).ready(function ()
{
    var id = getQueryString("id");

    layui.use('upload', function ()
    {
        form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        get_model_by_id(id);
    });

	$("#btn_submit").on("click", function(){
	
		 update();
	});

});


function get_model_by_id(id)
{
    $.ajax({
        type: "Get",
        url: ctx+"/system/dictinoaryType/get_model_by_id",
        data: { id: id },
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        error: function (request)
        {
            parent.layer.alert("Connection error");
        },
        success: function (data)
        {
            get_dictinoary_parentList("parent_id", form, data.parentId,data.id);
            $("#id").val(data.id);
            $("#dictinoary_value").val(data.dictinoaryValue);
            $("#dictinoary_name").val(data.dictinoaryName);
        }
    });
}

function update()
{
    var params = param();
    $.ajax({
        cache: true,
        type: "POST",
        url: ctx+"/system/dictinoaryType/update",
        data: params,
        async: false,
        error: function (request)
        {
            parent.layer.alert("更新失败");
        },
        success: function (data)
        {
            if (data.code == 0)
            {
                parent.layer.msg("操作成功");
                parent.reload();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);

            } else
            {
                parent.layer.alert(data.msg);
            }

        }
    });

}

function param()
{
    return {
        "id": $("#id").val(),
        "parentId": $("#parent_id").val(),
        "dictinoaryName": $("#dictinoary_name").val(),
        "dictinoaryValue": $("#dictinoary_value").val()
    };
}
